package Sort3;

public class SortCompare {
    //比较版本号，字符转为数字比较，一段一段的比较
    public int compare (String version1, String version2) {
        // write code here
        int l1=version1.length();
        int l2=version2.length();
        int i=0;
        int j=0;
        while(i<l1||j<l2){
            int num=0;
            while(i<l1&&version1.charAt(i)!='.'){
                num=num*10+(version1.charAt(i)-'0');
                i++;
            }
            i++;
            int num2=0;
            while(j<l2 && version2.charAt(j)!='.'){ //跳过点
                num2=num2*10+(version2.charAt(j)-'0');
                j++;
            }
            j++;
            if(num>num2){
                return 1;
            }if(num<num2){
                return -1;
            }
        }
        return 0;
    }
}
